package com.cndw.kungfu.model.goods.app;

import java.util.Map;

import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.domain.Pet;
import com.cndw.kungfu.domain.PetMode;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.exception.SysErrException;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.sys.ChatMain;
import com.cndw.kungfu.model.task.PlayerTasks;

/**
 * 打开获得宠物
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2012-4-7 下午2:51:36
 */
public class AppDo110 extends AppBase {

	@Override
	public boolean check() throws Exception {

		PetMode petMode = Context.getPetServer().getPetMode(goodsMode.getValueA());
		if (petMode == null) {
			throw new SysErrException();// 系统错误
		}
		if (petMode.getId() == 10 ) {
			PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
			if (!playerTasks.checkDoneOnce(56)) {
				throw new ErrPopException(LanguageLib.get("goods.use.petegg"));// 系统错误
			}
		}
		int haveNums = player.getDataInfo().getPetsMap().size();
		if (haveNums >= ConstantsModel.petMaxsNum) {
			throw new ErrPopException(LanguageLib.get("goods.use.petnum", ConstantsModel.petMaxsNum));
		}

		return true;
	}

	@Override
	public Map<String, Object> run() throws Exception {

		Pet pet = Context.getPetServer().insert(playerId, goodsMode.getValueA(), goodsMode.getValueB());
		if (pet == null) {
			throw new SysErrException();// 系统错误
		}
		if (player.getDataInfo().getPetsMap().size() <= 1) {
			player.getDataInfo().intDataSet(ConstantsIntKey.aPetBag, 1);
		}

		player.getDataInfo().getPetsMap().put(pet.getId(), pet);
		
		if (goodsId == 103230) {//神·白虎孵化蛋
			ChatMain.systemMessage(LanguageLib.get("goods.use.gettiger", player.getPlayerName()));
		}
		if (goodsId == 103229) {//神·玄武孵化蛋
			ChatMain.systemMessage(LanguageLib.get("goods.use.getturtle", player.getPlayerName()));
		}
		
		msg.put("pet", pet);
		ticpString = LanguageLib.get("goods.use.suc");
		return msg;
	}
}
